#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > cc_rsp_alpha.info <<'%EOF%'
   cc_rsp_alpha
   ------------
   Molecule:         HF in C1
   Wave Functions:   CCS, CCSD / 6-31G**
   Test Purpose:     Frequency-dependent polarizabilities and
                     dispersion coefficients
%EOF%

#######################################################################
#  INTEGRAL INPUT
#######################################################################
cat > cc_rsp_alpha.mol <<'%EOF%'
BASIS
6-31G**
Hydrogen flourid
small test basis
    2    0  Y  X      1.00D-15
        9.0   1    
F     0.0000000000000000  0.0000000000000000 1.76320000000000000      
        1.0   1
H     0.0000000000000000  0.0000000000000000 0.00000000000000000      
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > cc_rsp_alpha.dal <<'%EOF%'
**DALTON INPUT
.RUN WAVE FUNCTIONS
.DIRECT
**INTEGRAL
.DIPLEN
.ANGMOM
.THETA
**WAVE FUNCTIONS
.TITLE
  linear dipole-dipole and quadrupole-magnetic dipole
  polarizabilities for the HF molecule
  for CCS and CCSD wavefunctions
.CC
*SCF INPUT 
.THRESH
 1.0d-12
*CC INPUT 
.CCS
.CCSD
.THRENR
 1.0d-14
.THRLEQ
 1.0d-12
.PRINT
 1
.MAXRED
 400
.MXLRV
 400
*CCLR
.OLD_LR
.OPERATOR
ZDIPLEN ZDIPLEN
XDIPLEN XDIPLEN
XZTHETA YANGMOM
YANGMOM XZTHETA
.FREQUENCIES
  4
0.04282270  0.06562487 -0.04282270  -0.06562487
.DISPCF
  7
**END OF DALTON INPUT
%EOF%
#######################################################################

 

#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >cc_rsp_alpha.check
cat >>cc_rsp_alpha.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

# SCF, MP2 and CCSD energies:
CRIT1=`$GREP "Final * HF energy:" $log | $GREP "\-100.008919(8|9)." | wc -l`
CRIT2=`$GREP "Total MP2   energy:                  \-100.193662(5|6)." $log | wc -l`
CRIT3=`$GREP "Total CCSD  energy:                  \-100.1977909." $log | wc -l`
TESTA=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3` 
CTRLA=5
ERRORA="ENERGIES NOT CORRECT"

# CCS polarizabilities
CRIT1=`$GREP "<<ZDIPLEN ,ZDIPLEN >>\( ( |0)\.042823\) =    \-4.61250(7|8)" $log | wc -l`
CRIT2=`$GREP "<<ZDIPLEN ,ZDIPLEN >>\(( \-|\-0)\.042823\) =    \-4.61250(7|8)" $log | wc -l`
CRIT3=`$GREP "<<XDIPLEN ,XDIPLEN >>\( ( |0)\.042823\) =    \-1.973851" $log | wc -l`
CRIT4=`$GREP "<<XDIPLEN ,XDIPLEN >>\(( \-|\-0)\.042823\) =    \-1.973851" $log | wc -l`
CRIT5=`$GREP "<<XZTHETA ,YANGMOM >>\( ( |0)\.042823\) =    ( \-|\-0)\.261581" $log | wc -l`
CRIT6=`$GREP "<<XZTHETA ,YANGMOM >>\(( \-|\-0)\.042823\) =     ( |0)\.261581" $log | wc -l`
CRIT7=`$GREP "<<YANGMOM ,XZTHETA >>\( ( |0)\.042823\) =     ( |0)\.261581" $log | wc -l`
CRIT8=`$GREP "<<YANGMOM ,XZTHETA >>\(( \-|\-0)\.042823\) =    ( \-|\-0)\.261581" $log | wc -l`
TESTB=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ $CRIT7 \+ $CRIT8` 
CTRLB=8
ERRORB="CCS POLARIZABILITIES NOT CORRECT"

# CCSD polarizabilities
CRIT1=`$GREP "<<ZDIPLEN ,ZDIPLEN >>\( ( |0)\.042823\) =    \-4.586778" $log | wc -l`
CRIT2=`$GREP "<<XDIPLEN ,XDIPLEN >>\( ( |0)\.042823\) =    \-1.934298" $log | wc -l`
CRIT3=`$GREP "<<XZTHETA ,YANGMOM >>\( ( |0)\.042823\) =    ( \-|\-0)\.255863" $log | wc -l`
CRIT4=`$GREP "<<YANGMOM ,XZTHETA >>\( ( |0)\.042823\) =     ( |0)\.255863" $log | wc -l`
TESTC=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4` 
CTRLC=4
ERRORC="CCSD POLARIZABILITIES NOT CORRECT"


# CCS dispersion coeffiecients
CRIT1=`$GREP "ZDIPLEN     ZDIPLEN      \-4        388.073(6|7)." $log | wc -l`
CRIT2=`$GREP "                          6        48.7740(7|8|9)." $log | wc -l`
CRIT3=`$GREP "XZTHETA     YANGMOM       1        6.10416(2|3|4)." $log | wc -l`
CRIT4=`$GREP "                          7        21.028(8|9).." $log | wc -l`
CRIT5=`$GREP "YANGMOM     XZTHETA       1       \-6.10416(2|3|4)." $log | wc -l`
TESTD=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5` 
CTRLD=5
ERRORD="CCS DISPERSION COEFFICIENTS NOT CORRECT"


# CCSD dispersion coefficients
CRIT1=`$GREP "ZDIPLEN     ZDIPLEN      \-4        376.136(0|1)." $log | wc -l`
CRIT2=`$GREP "                          6        66.201(5|6).." $log | wc -l`
CRIT3=`$GREP "XDIPLEN     XDIPLEN      \-4        301.09(6|7).." $log | wc -l`
CRIT4=`$GREP "                          6        60.8(499|500).." $log | wc -l`
TESTE=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4` 
CTRLE=4
ERRORE="CCSD DISPERSION COEFFICIENTS NOT CORRECT"

# RPA sum rule
CRIT1=`$GREP "RPA RESULT:  \-8.37564(2|3).." $log | wc -l`
CRIT2=`$GREP "RPA RESULT:  \-8.846007.." $log | wc -l`
TESTF=`expr $CRIT1 \+ $CRIT2` 
CTRLF=2
ERRORF="RPA SUM RULES NOT CORRECT"

TESTSUM=`expr $TESTA \+ $TESTB \+ $TESTC \+ $TESTD \+ $TESTE \+ $TESTF`
CTRLSUM=`expr $CTRLA \+ $CTRLB \+ $CTRLC \+ $CTRLD \+ $CTRLE \+ $CTRLF`

if [ $TESTSUM -eq $CTRLSUM ]
then
  echo TEST ENDED PROPERLY
else

  if [ $TESTA -ne $CTRLA ]; then
    echo $ERRORA
  fi

  if [ $TESTB -ne $CTRLB ]; then
    echo $ERRORB
  fi

  if [ $TESTC -ne $CTRLC ]; then
    echo $ERRORC
  fi

  if [ $TESTD -ne $CTRLD ]; then
    echo $ERRORD
  fi

  if [ $TESTE -ne $CTRLE ]; then
    echo $ERRORE
  fi

  if [ $TESTF -ne $CTRLF ]; then
    echo $ERRORF
  fi

  echo THERE IS A PROBLEM 
  exit 1

fi

exit 0

%EOF%
chmod +x cc_rsp_alpha.check
#######################################################################
